#pragma once
#include "vn/File.h"

void FileTest() {_test_func_;

	// re throw test
	{
		try {
			Stream* s = File::OpenRead("khong co.txt");
			delete s;
		}
		catch (IOException &) {

		}

	}

	// File::Create
	{
		Stream*	ps = File::Create("_a.txt");
		String	msg = "Xin chao qui vi va cac ban";
		ps->Write((Buf8 *)msg.C_STR(), msg.GetLength() * sizeof(TChar));
		delete ps;

		REQUIRE_EXCEPTION( File::Create("") );
		REQUIRE_EXCEPTION( File::Create("t:\\nodisk.txt") );

	}

	// File::Open
	{
		Stream* ps = File::OpenRead("_a.txt");
		Buf8 buf[256];
		Int64 rc = ps->Read(buf, 256);
		buf[rc] = '\0';
		buf[rc+1] = '\0';
		String x = (TChar*)buf;
		assert(x == "Xin chao qui vi va cac ban");
		delete ps;

		REQUIRE_EXCEPTION( File::OpenRead("not_exist.txt") );
	}

	// File::Delete
	{
		REQUIRE_EXCEPTION( File::Delete("!@#$%^&*()") );
		REQUIRE_EXCEPTION( File::Delete("c:\\windows__\\a.txt") );
		File::Delete("khong co.txt");
	}

	// File::Exist
	{
		assert(File::Exists("_a.txt") == true);
		assert(File::Exists("not_exist.txt") == false);
	}

	// File::Copy
	{
		File::Delete("c:\\_a.txt");

		File::Copy("_a.txt", "c:\\_a.txt");

		assert(File::Exists("_a.txt"));
		assert(File::Exists("c:\\_a.txt"));

		REQUIRE_EXCEPTION( File::Copy("not_exist.txt", "c:\\_a.txt") );
	}


	// File::Move
	{
		REQUIRE_EXCEPTION( File::Move("khong co.txt", "khong co.txt") );
		( File::Move("c:\\_a.txt", "c:\\_a.txt") );

		( File::Move("c:\\_a.txt", "c:\\_b.txt") );
		( File::Move("c:\\_b.txt", "c:\\_a.txt") );


		File::Delete("d:\\_a.txt");

		File::Move("c:\\_a.txt", "D:\\_a.txt");
		assert(File::Exists("c:\\_a.txt") == false);
		assert(File::Exists("d:\\_a.txt") == true);
	}

	// File::FileSize
	{

	}


}

